from die import Die
import plotly.express as px

# 创建2个D6
die_1 = Die()
die_2 = Die()

#  掷骰⼦多次，并将结果存储到⼀个列表中
results = []
for roll_num in range(1000):
    result = die_1.roll() + die_2.roll()
    results.append(result)

# print(results)

# 分析结果
frequencies = []
max_result = die_1.num_sides + die_2.num_sides # 两个色子最大值
poss_results = range(2, max_result+1) # 两个色子可以甩出的所有结果
# print(pross_results)
for value in poss_results:
    frequencies.append(results.count(value)) # 统计每个面出现的次数，并添加到分析结果frequencies列表中
    
print(frequencies)



# 图设置
title = "Results of Rolling One D6 1,000 Times"       
labels = {'x': 'Result', 'y': 'Frequency of Result'}  # x,y轴的标题

# 直方图
# fig = px.bar(x=poss_results, y=frequencies)   # 不设置x,y轴标题

# 点位图
# fig = px.scatter(x=poss_results, y=frequencies, title=title, labels=labels)

# 折线图
fig = px.line(x=poss_results, y=frequencies, title=title, labels=labels)

# update_layout() ⽅法，可⽤来对创建的图形做各种修改
# 每个条形都加上标签
fig.update_layout(xaxis_dtick=1)

fig.show()